#include "gettargetrequest.h"

//全部清除，传-1
//QByteArray GetTargetRequest::requestDateApi(int addr)
//{
//    if(addr<0){
//      Send_Info sendDataInfo;
//      sendDataInfo.code = ClearTarget;
//      sendDataInfo.data.insert("addr",-1);
//      QByteArray data = structToJson(sendDataInfo);
//      return data;
//    }
//    else{
//          Send_Info sendDataInfo;
//          sendDataInfo.code = ClearTarget;
//          sendDataInfo.data.insert("addr",addr);
//          QByteArray data = structToJson(sendDataInfo);
//          return data;
//    }
//}



QByteArray GetTargetRequest::sendGroupNumberApi(int groupNumber)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = UserGrouping;
  sendDataInfo.data.insert("group_number",groupNumber);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::sendYuanXinApi(int old_addr, int new_addr)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = RewriteTargetId;
  sendDataInfo.data.insert("old_addr",old_addr);
  sendDataInfo.data.insert("new_addr",new_addr);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::sendBeginApi(int flag)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = OpenCalibrationTargetById;
  sendDataInfo.data.insert("addr",flag);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::sendOverApi(int flag)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = CloseCalibrationTargetById;
  sendDataInfo.data.insert("addr",flag);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::sendSearchDataApi(int fenZu, int baHao, const QString &time)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = GetShowInfo;
  sendDataInfo.msg.insert("date",time);
  sendDataInfo.data.insert("addr",baHao);
  sendDataInfo.data.insert("group_number",fenZu);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::sendHolesApi(int msg, int group_number)
{
  QDate m_date = QDate::currentDate();
  QString currentDate = m_date.toString("yyyy-MM-dd");
  Send_Info sendDataInfo;
  sendDataInfo.code = GetTargetInfo;
  sendDataInfo.msg.insert("date",currentDate);
  sendDataInfo.data.insert("addr",msg);
  sendDataInfo.data.insert("group_number",group_number);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}


QByteArray GetTargetRequest::currentTargetBulletApi(const OneTaregtBullet& oneTaregtBullet)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = CurrentBullet;
  sendDataInfo.data.insert("addr",oneTaregtBullet.addr);
  sendDataInfo.data.insert("x",oneTaregtBullet.x);
  sendDataInfo.data.insert("y",oneTaregtBullet.y);
  sendDataInfo.data.insert("cn",oneTaregtBullet.cylinder_number);
  sendDataInfo.data.insert("dir",oneTaregtBullet.direction);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}



QByteArray GetTargetRequest::pushTargetStateInfoApi()
{
  Send_Info sendDataInfo;
  sendDataInfo.code = GetTargetState;
  QReadLocker readLocker(&StateOfTargetMapRwLock);
  foreach(int key, StateOfTargetMap.keys())
    {
      int value = StateOfTargetMap.value(key);
      QString addr = QString::number(key);
      sendDataInfo.data.insert(addr,value);
    }
  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::pushTargetVoltageInfoApi()
{
  Send_Info sendDataInfo;
  sendDataInfo.code = GetVoltage;
  QReadLocker readLocker(&StateOfTargetMapRwLock);
  foreach(int key, VoltageOfTargetMap.keys())
    {
      int value = VoltageOfTargetMap.value(key);
      QString addr = QString::number(key);
      sendDataInfo.data.insert(addr,value);
    }

  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::requestStateApi()
{
  Send_Info sendDataInfo;
  sendDataInfo.code = GetTargetState;
  QByteArray dataState = structToJson(sendDataInfo);
  return dataState;
}

QByteArray GetTargetRequest::requestBatteryApi()
{
  Send_Info sendDataInfo;
  sendDataInfo.code = GetVoltage;
  QByteArray dataBattery  = structToJson(sendDataInfo);
  return dataBattery;
}

QByteArray GetTargetRequest::requestClearAllApi()
{
  Send_Info sendDataInfo;
  sendDataInfo.code = ClearTarget;
  sendDataInfo.data.insert("addr",-1);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::requestClearOnlyApi(int index2)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = ClearTarget;
  sendDataInfo.data.insert("addr",index2);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}



QByteArray GetTargetRequest::bindInfoApi(int addr, const QString &name, const QString &idCard)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = BindInfo;
  sendDataInfo.msg.insert("user_name",name);
  sendDataInfo.msg.insert("identification_number",idCard);
  sendDataInfo.data.insert("addr",addr);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::sendIdApi(int addr)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = ChangeSystemId;
  sendDataInfo.data.insert("addr",addr);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}

QByteArray GetTargetRequest::sendCheckXandYApi(int addr,int x, int y)
{
  Send_Info sendDataInfo;
  sendDataInfo.code = TwoCheck;
  sendDataInfo.data.insert("addr",addr);
  sendDataInfo.data.insert("x",x);
  sendDataInfo.data.insert("y",y);
  QByteArray data = structToJson(sendDataInfo);
  return data;
}
